/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-11-13
 * Time: 19:07
 */
class MyCircularQueue {

    int[] nums;
    int front;
    int rear;

//    构造方法
    public MyCircularQueue(int k) {
        this.nums = new int[k + 1];
    }

//    向循环队列插入一个元素
    public boolean enQueue(int value) {
        if (this.isFull()){
            return false;
        }
        this.nums[this.front] = value;
        this.front = (this.front + 1) % this.nums.length;
        return true;
    }

//    从循环队列中删除一个元素
    public boolean deQueue() {
        if (this.isEmpty()){
            return false;
        }
        this.rear = (this.rear + 1) % this.nums.length;
        return true;
    }

//    获取队列的队头元素
    public int Front() {
        if (this.isEmpty()){
            return -1;
        }
        return this.nums[this.rear];
    }

//    获取队列的队尾元素
    public int Rear() {
        if (this.isEmpty()){
            return -1;
        }
        return this.nums[this.front == 0 ? this.nums.length - 1 : this.front - 1];
    }

//    判断循环队列是否为空
    public boolean isEmpty() {
        return this.rear == this.front;
    }

//    判断循环队列是否已满
    public boolean isFull() {
        return ((this.front + 1) % this.nums.length) == this.rear;
    }
}
